﻿using Common;
using DevExpress.XtraEditors;
using DLL;
using NursingFormSystem.Common;
using NursingFormSystem.Model;
using NursingFormSystem.NurFormsService;
using SQLDLL;
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;

namespace NursingFormSystem.SingleDelivery
{
    public partial class AddSingleDelivery : Form
    {
        string Id;
        Tb_User LoginUser;
        PatientInfo PatientInfo;
        NursingFormRecord record = new NursingFormRecord();
        NursingForm formService = new NursingForm();
        public AddSingleDelivery(Tb_User loginUser, PatientInfo patientInfo)
        {
            InitializeComponent();
            this.PatientInfo = patientInfo;
            this.LoginUser = loginUser;
            BindControl();
            BindInfo(this.Id);
        }
        public AddSingleDelivery(string[] loginUser, string[] patientInfo)
        {
            InitializeComponent();
            this.PatientInfo = ArrayToObject.ArrayToPatientInfo(patientInfo);
            this.LoginUser = ArrayToObject.ArrayToLoginUser(loginUser);
            BindControl();
            BindInfo(this.Id);
        }

        private void BindControl()
        {
            foreach (var c in groupControl1.Controls)
            {
                if (c is TextEdit)
                {
                    ((TextEdit)c).KeyUp += TextEdit_KeyUp;
                }
            }
            this.chkRenShenBingFaZheng16.CheckedChanged += chkRenShenBingFaZheng16_CheckedChanged;
            this.chkRenShenHeBingZheng20.CheckedChanged += chkRenShenHeBingZheng20_CheckedChanged;
        }

        void chkRenShenHeBingZheng20_CheckedChanged(object sender, EventArgs e)
        {
            if (chkRenShenHeBingZheng20.Checked)
            {
                textEdit11chkRenShenHeBingZheng_QiTaYanZhongNeiWaiKeJiBing_Text.Visible = true;
            }
            else
            {
                textEdit11chkRenShenHeBingZheng_QiTaYanZhongNeiWaiKeJiBing_Text.Visible = false;
                textEdit11chkRenShenHeBingZheng_QiTaYanZhongNeiWaiKeJiBing_Text.Text = string.Empty;
            }
        }

        void chkRenShenBingFaZheng16_CheckedChanged(object sender, EventArgs e)
        {
            if (chkRenShenBingFaZheng16.Checked)
            {
                chkRenShenBingFaZheng_QiTaYanZhong_Text.Visible = true;
            }
            else
            {
                chkRenShenBingFaZheng_QiTaYanZhong_Text.Visible = false;
                chkRenShenBingFaZheng_QiTaYanZhong_Text.Text = string.Empty;
            }
        }
        /// <summary>
        /// 设置 enter键当做Tab切换
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TextEdit_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyData == Keys.Enter)
            {
                SendKeys.SendWait("{Tab}");
            }
        }
        private void BindInfo(string id)
        {
            textJiLuZhe.Text = LoginUser.UserName;
            var ret = formService.GetNursingFormRecordOrderByTime(PatientInfo.PATIENT_ID, PatientInfo.VISIT_ID, (int)FormType.Parturitions, 1);
            if (ret.Code == 1)
            {
                List<NursingFormRecord> list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<NursingFormRecord>>(ret.D);
                if (string.IsNullOrEmpty(this.Id))
                    record = list[0];
                else
                    record = list.Find(p => p.Id == Convert.ToInt32(this.Id));
                this.Id = record.Id.ToString();
                var NursingFormData = record.NursingFormData;
                Parturition pat = new Parturition();
                pat = XmlUtil.XMLToObject<Parturition>(NursingFormData, Encoding.UTF8);

                dataZhenSuoKaiShi.Text = pat.ZhenSuoKaiShi;
                dateTaiMoPoLie.Text = pat.TaiMoPoLie_ShiJian;
                comTaiMoPoLie_xiakaluang.Text = pat.TaiMoPoLie_Text;
                comYangShui.Text = pat.YangShui;
                dateGongKouKaiQuan.Text = pat.GongKouKaiQuan;
                textDiYiChanCheng_Shi.Text = pat.DiYiChanChen_Shi;
                textDiYiChanCheng_Fen.Text = pat.DiYiChanChen_Fen;
                comFenHouYangShui.Text = pat.FenHouYangShui;
                dateTaiErMianChu_1.Text = pat.TaiErMianChu_One;
                dateTaiErMianChu_2.Text = pat.TaiErMianChu_Two;
                textDiErChanCheng_Shi.Text = pat.DiErChanChen_Shi;
                textDiErChanCheng_Fen.Text = pat.DiErChanChen_Fen;
                dateTaiPanMianChu.Text = pat.TaiPanMianChu;
                textDiSanChanCheng_Shi.Text = pat.DiSanChanChen_Shi;
                textDiSanChanCheng_Fen.Text = pat.DiSanChanChen_Fen;
                textZongChanCheng_Shi.Text = pat.ZongChanCheng_Shi;
                textZongChanCheng_Fen.Text = pat.ZongChanCheng_Fen;
                comFenMianFangShi.Text = pat.FenMianFangShi;
                comFenMianFangShi2.Text = pat.FenMianFangShi2;
                textFenMianFangShi_Text.Text = pat.FenMianFangShi_Text;
                comboTaiChanWei.Text = pat.TaiChanWei;
                comTaiPanFangShi_1.Text = pat.TaiPanFangShi_1;
                comTaiPanFangShi_2.Text = pat.TaiPanFangShi_2;
                textTiJi.Text = pat.TiJi;
                textZhongLiang.Text = pat.ZhongLiang;
                comTaiPanQingKuang.Text = pat.TaiPanQingKuang;
                comTaiMo.Text = pat.TaiMo;
                textQiDaiChang.Text = pat.QiDaiChang;
                textRaoJing_Zhou.Text = pat.RaoJing_Zhou;
                comRaoJing_XiaLaKuang.Text = pat.RaoJing_XiaLaXuanXiang;
                textTaiPanMianChuShiChuXue.Text = pat.TaiPanMianChuShiChuXue;
                textChanHouSanShiChuXue.Text = pat.ChanHouSanShiChuXue;
                textSiWuChuXue.Text = pat.SiWu;
                textLiuShiChuXue.Text = pat.LiuShi;
                textJiuShiChuXue.Text = pat.JiuShi;
                textYiBaiErChuXue.Text = pat.YiBaiEr;
                textChanHouLiangXiaoShiZongChuLiang.Text = pat.ChanHouLiangXiaoShiZongChuXueLiang;
                textChanHouXueYa_Di.Text = pat.ChanHouXueYa_Di;
                textChanHouXueYa_Gao.Text = pat.ChanHouXueYa_Gao;
                textChanShiYongYao_CuiChanSuZhuShe_Liang.Text = pat.ChanShiYongYao_CuiChanSuZhuShe_Liang;
                textChanShiYongYao_BuWei.Text = pat.ChanShiYongYao_BuWei;
                textChanShiYongYao_QiTa.Text = pat.ChanShiYongYao_QiTa;
                textXingBie.Text = pat.XinShengEr_XingBie;
                textTiZhong.Text = pat.XinShengEr_TiZhong;
                textShenChang.Text = pat.XinShengEr_ShenChang;
                comAPgar.Text = pat.APgar_PingFen;

                textXingBie2.Text = pat.XinShengEr_XingBie2;
                textXingBie2.Enabled = true;
                textTiZhong2.Text = pat.XinShengEr_TiZhong2;
                textTiZhong2.Enabled = true;
                textShenChang2.Text = pat.XinShengEr_ShenChang2;
                textShenChang2.Enabled = true;
                comAPgar2.Text = pat.APgar_PingFen2;
                comAPgar2.Enabled = true;

                comHhuYinPoLie.Text = pat.HuiYinPoLie;
                textNeiFeng_Zhen.Text = pat.NeiFeng_Zhen;
                textNeiFeng_Xian.Text = pat.NeiFeng_Xian;
                textWaiFeng_Zhen.Text = pat.WaiFeng_Zhen;
                textWaiFeng_Xian.Text = pat.WaiFeng_Xian;
                textYinChunPoLie.Text = pat.YinChunPoLie;
                textYinDaoPoLie.Text = pat.YinDaoPoLie;
                textGongJingPoKai.Text = pat.GongJingLieKai;
                textXiuBuZhe.Text = pat.XiuBuZhe;
                comHuiYinFengHeHouGangJIan.Text = pat.HuiYinFengHeHouGangJian;
                textHuiYinFengHeHouGangJIan_Text.Text = pat.HuiYinFengHeHouGangJian_Text;
                textZhenDuan_Tai.Text = pat.ZhenDuan_Tai;
                textZhenDuan_Chan.Text = pat.ZhenDuan_Chan;
                textZhenDuan_Zhou.Text = pat.ZhenDuan_Zhou;
                textZhenDuan_Mian.Text = pat.ZhenDuan_Mian;
                comTaiFangWei.Text = pat.TaiFangWei;

                if (!string.IsNullOrEmpty(pat.RenShenBingFaZheng))
                {
                    chkRenShenBingFaZheng1.Checked = pat.RenShenBingFaZheng.Split('#')[0].Equals("1");
                    chkRenShenBingFaZheng2.Checked = pat.RenShenBingFaZheng.Split('#')[1].Equals("1");
                    chkRenShenBingFaZheng3.Checked = pat.RenShenBingFaZheng.Split('#')[2].Equals("1");
                    chkRenShenBingFaZheng4.Checked = pat.RenShenBingFaZheng.Split('#')[3].Equals("1");
                    chkRenShenBingFaZheng5.Checked = pat.RenShenBingFaZheng.Split('#')[4].Equals("1");
                    chkRenShenBingFaZheng6.Checked = pat.RenShenBingFaZheng.Split('#')[5].Equals("1");
                    chkRenShenBingFaZheng7.Checked = pat.RenShenBingFaZheng.Split('#')[6].Equals("1");
                    chkRenShenBingFaZheng8.Checked = pat.RenShenBingFaZheng.Split('#')[7].Equals("1");
                    chkRenShenBingFaZheng9.Checked = pat.RenShenBingFaZheng.Split('#')[8].Equals("1");
                    chkRenShenBingFaZheng10.Checked = pat.RenShenBingFaZheng.Split('#')[9].Equals("1");
                    chkRenShenBingFaZheng11.Checked = pat.RenShenBingFaZheng.Split('#')[10].Equals("1");
                    chkRenShenBingFaZheng12.Checked = pat.RenShenBingFaZheng.Split('#')[11].Equals("1");
                    chkRenShenBingFaZheng13.Checked = pat.RenShenBingFaZheng.Split('#')[12].Equals("1");
                    chkRenShenBingFaZheng14.Checked = pat.RenShenBingFaZheng.Split('#')[13].Equals("1");
                    chkRenShenBingFaZheng15.Checked = pat.RenShenBingFaZheng.Split('#')[14].Equals("1");
                    chkRenShenBingFaZheng16.Checked = (pat.RenShenBingFaZheng.Split('#').Length >= 16 && pat.RenShenBingFaZheng.Split('#')[15].Equals("1"));
                    chkRenShenBingFaZheng17.Checked = (pat.RenShenBingFaZheng.Split('#').Length >= 17 && pat.RenShenBingFaZheng.Split('#')[16].Equals("1"));
                    chkRenShenBingFaZheng18.Checked = (pat.RenShenBingFaZheng.Split('#').Length >= 18 && pat.RenShenBingFaZheng.Split('#')[17].Equals("1"));
                }
                chkRenShenBingFaZheng_QiTaYanZhong_Text.Visible = false;
                chkRenShenBingFaZheng_QiTaYanZhong_Text.Visible = chkRenShenBingFaZheng16.Checked;
                chkRenShenBingFaZheng_QiTaYanZhong_Text.Text = pat.RenShenBingFaZheng_Text;

                if (!string.IsNullOrEmpty(pat.RenShenHeBingZheng))
                {
                    chkRenShenHeBingZheng1.Checked = pat.RenShenHeBingZheng.Split('#')[0].Equals("1");
                    chkRenShenHeBingZheng2.Checked = pat.RenShenHeBingZheng.Split('#')[1].Equals("1");
                    chkRenShenHeBingZheng3.Checked = pat.RenShenHeBingZheng.Split('#')[2].Equals("1");
                    chkRenShenHeBingZheng4.Checked = pat.RenShenHeBingZheng.Split('#')[3].Equals("1");
                    chkRenShenHeBingZheng5.Checked = pat.RenShenHeBingZheng.Split('#')[4].Equals("1");
                    chkRenShenHeBingZheng6.Checked = pat.RenShenHeBingZheng.Split('#')[5].Equals("1");
                    chkRenShenHeBingZheng7.Checked = pat.RenShenHeBingZheng.Split('#')[6].Equals("1");
                    chkRenShenHeBingZheng8.Checked = pat.RenShenHeBingZheng.Split('#')[7].Equals("1");
                    chkRenShenHeBingZheng9.Checked = pat.RenShenHeBingZheng.Split('#')[8].Equals("1");
                    chkRenShenHeBingZheng10.Checked = pat.RenShenHeBingZheng.Split('#')[9].Equals("1");
                    chkRenShenHeBingZheng11.Checked = pat.RenShenHeBingZheng.Split('#')[10].Equals("1");
                    chkRenShenHeBingZheng12.Checked = pat.RenShenHeBingZheng.Split('#')[11].Equals("1");
                    chkRenShenHeBingZheng13.Checked = pat.RenShenHeBingZheng.Split('#')[12].Equals("1");
                    chkRenShenHeBingZheng14.Checked = pat.RenShenHeBingZheng.Split('#')[13].Equals("1");
                    chkRenShenHeBingZheng15.Checked = pat.RenShenHeBingZheng.Split('#')[14].Equals("1");
                    chkRenShenHeBingZheng16.Checked = pat.RenShenHeBingZheng.Split('#')[15].Equals("1");
                    chkRenShenHeBingZheng17.Checked = pat.RenShenHeBingZheng.Split('#')[16].Equals("1");
                    chkRenShenHeBingZheng18.Checked = pat.RenShenHeBingZheng.Split('#')[17].Equals("1");
                    chkRenShenHeBingZheng19.Checked = pat.RenShenHeBingZheng.Split('#')[18].Equals("1");
                    chkRenShenHeBingZheng20.Checked = pat.RenShenHeBingZheng.Split('#').Length >= 20 && pat.RenShenHeBingZheng.Split('#')[19].Equals("1");
                }
                textEdit11chkRenShenHeBingZheng_QiTaYanZhongNeiWaiKeJiBing_Text.Visible = false;
                textEdit11chkRenShenHeBingZheng_QiTaYanZhongNeiWaiKeJiBing_Text.Visible = chkRenShenHeBingZheng20.Checked;
                textEdit11chkRenShenHeBingZheng_QiTaYanZhongNeiWaiKeJiBing_Text.Text = pat.RenShenHeBingZheng_Text;

                comYingErZaoJieChu_FenZhong.Text = pat.YingErPiFuZaoJieChuZaoXiShunFenZhong;   //婴儿皮肤早接触、早吸吮产_分钟
                comYingErZaoJieChu_ChiXuFenZhong.Text = pat.YingErPiFuZaoJieChuZaoXiShunFenZhong_ChiXuFenZhong;  //婴儿皮肤早接触、早吸吮产_持续分数
                comYingErZaoJieChu_XiShunQingKuang.Text = pat.YingErPiFuZaoJieChuZaoXiShunFenZhong_XiShunQingKuang;    //婴儿皮肤早接触、早吸吮产_吸吮情况
                textWeiXingPiFuZaoJieChuZaoXiShunYuanYin.Text = pat.WeiXingPiFuZaoJieChuZoXiShunYuanYin; //未行皮肤早接触、早吸吮原因
                memoBeiZhu.Text = pat.BeiZhu;   //备注
                textChanFuLiKaiChnFangShiJian.Text = pat.ChanFuLiKaiChnFangShiJian;  //产妇离开产房时间
                textJieShengZhe.Text = pat.JieShengZhe;   //接生者
                textJieShengZhe2.Text = pat.JieShengZhe2;   //接生者2
                textJieShengZhe3.Text = pat.JieShengZhe3;   //接生者3
                textJiLuZhe.Text = pat.JiLuZhe;//记录者
            }
            else if (ret.Code == 2)
            {
                this.Id = string.Empty;
                return;
            }
            else
            {
                MessageBox.Show(ret.M);
            }
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            Parturition pat = new Parturition();
            pat.ZhenSuoKaiShi = dataZhenSuoKaiShi.Text;
            pat.TaiMoPoLie_ShiJian = dateTaiMoPoLie.Text;
            pat.TaiMoPoLie_Text = comTaiMoPoLie_xiakaluang.Text;
            pat.YangShui = comYangShui.Text;
            pat.GongKouKaiQuan = dateGongKouKaiQuan.Text;
            pat.DiYiChanChen_Shi = textDiYiChanCheng_Shi.Text;
            pat.DiYiChanChen_Fen = textDiYiChanCheng_Fen.Text;
            pat.FenHouYangShui = comFenHouYangShui.Text;
            pat.TaiErMianChu_One = dateTaiErMianChu_1.Text;
            pat.TaiErMianChu_Two = dateTaiErMianChu_2.Text;
            pat.DiErChanChen_Shi = textDiErChanCheng_Shi.Text;
            pat.DiErChanChen_Fen = textDiErChanCheng_Fen.Text;
            pat.TaiPanMianChu = dateTaiPanMianChu.Text;
            pat.DiSanChanChen_Shi = textDiSanChanCheng_Shi.Text;
            pat.DiSanChanChen_Fen = textDiSanChanCheng_Fen.Text;
            pat.ZongChanCheng_Shi = textZongChanCheng_Shi.Text;
            pat.ZongChanCheng_Fen = textZongChanCheng_Fen.Text;
            pat.FenMianFangShi = comFenMianFangShi.Text;
            pat.FenMianFangShi2 = comFenMianFangShi2.Text;
            if (!comFenMianFangShi2.Visible)
                pat.FenMianFangShi2 = string.Empty;
            pat.FenMianFangShi_Text = textFenMianFangShi_Text.Text;
            if (!textFenMianFangShi_Text.Visible)
                pat.FenMianFangShi_Text = string.Empty;
            pat.TaiChanWei = comboTaiChanWei.Text;
            pat.TaiPanFangShi_1 = comTaiPanFangShi_1.Text;
            pat.TaiPanFangShi_2 = comTaiPanFangShi_2.Text;
            pat.TiJi = textTiJi.Text;
            pat.ZhongLiang = textZhongLiang.Text;
            pat.TaiPanQingKuang = comTaiPanQingKuang.Text;
            pat.TaiMo = comTaiMo.Text;
            pat.QiDaiChang = textQiDaiChang.Text;
            pat.RaoJing_Zhou = textRaoJing_Zhou.Text;
            pat.RaoJing_XiaLaXuanXiang = comRaoJing_XiaLaKuang.Text;
            pat.TaiPanMianChuShiChuXue = textTaiPanMianChuShiChuXue.Text;
            pat.ChanHouSanShiChuXue = textChanHouSanShiChuXue.Text;
            pat.SiWu = textSiWuChuXue.Text;
            pat.LiuShi = textLiuShiChuXue.Text;
            pat.JiuShi = textJiuShiChuXue.Text;
            pat.YiBaiEr = textYiBaiErChuXue.Text;
            pat.ChanHouLiangXiaoShiZongChuXueLiang = textChanHouLiangXiaoShiZongChuLiang.Text;
            pat.ChanHouXueYa_Di = textChanHouXueYa_Di.Text;
            pat.ChanHouXueYa_Gao = textChanHouXueYa_Gao.Text;
            pat.ChanShiYongYao_CuiChanSuZhuShe_Liang = textChanShiYongYao_CuiChanSuZhuShe_Liang.Text;
            pat.ChanShiYongYao_BuWei = textChanShiYongYao_BuWei.Text;
            pat.ChanShiYongYao_QiTa = textChanShiYongYao_QiTa.Text;
            pat.XinShengEr_XingBie = textXingBie.Text;
            pat.XinShengEr_TiZhong = textTiZhong.Text;
            pat.XinShengEr_ShenChang = textShenChang.Text;
            pat.APgar_PingFen = comAPgar.Text;
            pat.XinShengEr_XingBie2 = textXingBie2.Text;
            pat.XinShengEr_TiZhong2 = textTiZhong2.Text;
            pat.XinShengEr_ShenChang2 = textShenChang2.Text;
            pat.APgar_PingFen2 = comAPgar2.Text;
            pat.HuiYinPoLie = comHhuYinPoLie.Text;
            pat.NeiFeng_Zhen = textNeiFeng_Zhen.Text;
            pat.NeiFeng_Xian = textNeiFeng_Xian.Text;
            pat.WaiFeng_Zhen = textWaiFeng_Zhen.Text;
            pat.WaiFeng_Xian = textWaiFeng_Xian.Text;
            pat.YinChunPoLie = textYinChunPoLie.Text;
            pat.YinDaoPoLie = textYinDaoPoLie.Text;
            pat.GongJingLieKai = textGongJingPoKai.Text;
            pat.XiuBuZhe = textXiuBuZhe.Text;
            pat.HuiYinFengHeHouGangJian = comHuiYinFengHeHouGangJIan.Text;
            pat.HuiYinFengHeHouGangJian_Text = textHuiYinFengHeHouGangJIan_Text.Text;
            pat.ZhenDuan_Tai = textZhenDuan_Tai.Text;
            pat.ZhenDuan_Chan = textZhenDuan_Chan.Text;
            pat.ZhenDuan_Zhou = textZhenDuan_Zhou.Text;
            pat.ZhenDuan_Mian = textZhenDuan_Mian.Text;
            pat.TaiFangWei = comTaiFangWei.Text;
            pat.RenShenBingFaZheng = (chkRenShenBingFaZheng1.Checked ? 1 : 0) + "#" + (chkRenShenBingFaZheng2.Checked ? 1 : 0) + "#" + (chkRenShenBingFaZheng3.Checked ? 1 : 0)
                 + "#" + (chkRenShenBingFaZheng4.Checked ? 1 : 0) + "#" + (chkRenShenBingFaZheng5.Checked ? 1 : 0) + "#" + (chkRenShenBingFaZheng6.Checked ? 1 : 0)
                  + "#" + (chkRenShenBingFaZheng7.Checked ? 1 : 0) + "#" + (chkRenShenBingFaZheng8.Checked ? 1 : 0) + "#" + (chkRenShenBingFaZheng9.Checked ? 1 : 0)
                   + "#" + (chkRenShenBingFaZheng10.Checked ? 1 : 0) + "#" + (chkRenShenBingFaZheng11.Checked ? 1 : 0) + "#" + (chkRenShenBingFaZheng12.Checked ? 1 : 0)
                    + "#" + (chkRenShenBingFaZheng13.Checked ? 1 : 0) + "#" + (chkRenShenBingFaZheng14.Checked ? 1 : 0) + "#" + (chkRenShenBingFaZheng15.Checked ? 1 : 0)
                    + "#" + (chkRenShenBingFaZheng16.Checked ? 1 : 0) + "#" + (chkRenShenBingFaZheng17.Checked ? 1 : 0) + "#" + (chkRenShenBingFaZheng18.Checked ? 1 : 0);
            pat.RenShenBingFaZheng_Text = chkRenShenBingFaZheng_QiTaYanZhong_Text.Text;

            pat.RenShenHeBingZheng = (chkRenShenHeBingZheng1.Checked ? 1 : 0) + "#" + (chkRenShenHeBingZheng2.Checked ? 1 : 0) + "#" + (chkRenShenHeBingZheng3.Checked ? 1 : 0)
                + "#" + (chkRenShenHeBingZheng4.Checked ? 1 : 0) + "#" + (chkRenShenHeBingZheng5.Checked ? 1 : 0) + "#" + (chkRenShenHeBingZheng6.Checked ? 1 : 0)
                + "#" + (chkRenShenHeBingZheng7.Checked ? 1 : 0) + "#" + (chkRenShenHeBingZheng8.Checked ? 1 : 0) + "#" + (chkRenShenHeBingZheng9.Checked ? 1 : 0)
                + "#" + (chkRenShenHeBingZheng10.Checked ? 1 : 0) + "#" + (chkRenShenHeBingZheng11.Checked ? 1 : 0) + "#" + (chkRenShenHeBingZheng12.Checked ? 1 : 0)
                + "#" + (chkRenShenHeBingZheng13.Checked ? 1 : 0) + "#" + (chkRenShenHeBingZheng14.Checked ? 1 : 0) + "#" + (chkRenShenHeBingZheng15.Checked ? 1 : 0)
                + "#" + (chkRenShenHeBingZheng16.Checked ? 1 : 0) + "#" + (chkRenShenHeBingZheng17.Checked ? 1 : 0) + "#" + (chkRenShenHeBingZheng18.Checked ? 1 : 0)
                + "#" + (chkRenShenHeBingZheng19.Checked ? 1 : 0) + "#" + (chkRenShenHeBingZheng20.Checked ? 1 : 0);

            pat.RenShenHeBingZheng_Text = textEdit11chkRenShenHeBingZheng_QiTaYanZhongNeiWaiKeJiBing_Text.Text;

            pat.YingErPiFuZaoJieChuZaoXiShunFenZhong = comYingErZaoJieChu_FenZhong.Text;   //婴儿皮肤早接触、早吸吮产_分钟
            pat.YingErPiFuZaoJieChuZaoXiShunFenZhong_ChiXuFenZhong = comYingErZaoJieChu_ChiXuFenZhong.Text;  //婴儿皮肤早接触、早吸吮产_持续分数
            pat.YingErPiFuZaoJieChuZaoXiShunFenZhong_XiShunQingKuang = comYingErZaoJieChu_XiShunQingKuang.Text;    //婴儿皮肤早接触、早吸吮产_吸吮情况
            pat.WeiXingPiFuZaoJieChuZoXiShunYuanYin = textWeiXingPiFuZaoJieChuZaoXiShunYuanYin.Text; //未行皮肤早接触、早吸吮原因
            pat.BeiZhu = memoBeiZhu.Text;   //备注
            pat.ChanFuLiKaiChnFangShiJian = textChanFuLiKaiChnFangShiJian.Text;  //产妇离开产房时间
            pat.JieShengZhe = textJieShengZhe.Text;   //接生者
            pat.JieShengZhe2 = textJieShengZhe2.Text;   //接生者2
            pat.JieShengZhe3 = textJieShengZhe3.Text;   //接生者3
            pat.JiLuZhe = string.IsNullOrEmpty(this.Id) ? LoginUser.UserName : textJiLuZhe.Text;  //记录者
            pat.FormId = (int)FormType.Parturitions;
            pat.FormName = EnumHelper.GetDescription(FormType.Parturitions);
            record.NursingFormData = XmlUtil.ObjectToXML(pat, Encoding.UTF8);
            record.FormId = pat.FormId;//表单ID
            record.FormName = pat.FormName;//表单NAME
            record.PatientId = PatientInfo.PATIENT_ID;//住院号
            record.VisitId = PatientInfo.VISIT_ID;//住院次数
            record.PatientName = PatientInfo.PATIENT_NAME;//患者名称
            record.BedNo = PatientInfo.BED_NO;//床号
            record.DepartmentId = PatientInfo.DEPARTMENT_ID;//科室号
            record.DepartmentName = PatientInfo.DEPARTMENT_NAME;//科室名称
            record.AreaId = PatientInfo.NURSE_CELL_CODE;//病区编号
            record.AreaName = PatientInfo.NURSE_CELL_NAME;//病区名称
            record.AssessmentDate = DateTime.Now;//日期       

            record.Id = string.IsNullOrEmpty(Id) ? 0 : Convert.ToInt32(Id);
            var ret = formService.SetNursingFormRecord(Newtonsoft.Json.JsonConvert.SerializeObject(record));

            if (ret.Code == 1)
            {
                //电签开始
                if (Base.ESSwitch.Equals("on"))
                {
                    string extraInfo = "<?xml version=\"1.0\" encoding=\"UTF-16\"?><root><sign_sys>{0}</sign_sys><title>{1}</title><patient_id>{2}</patient_id><patient_name>{3}</patient_name><emr_id>{4}</emr_id><emr_catalog>{5}</emr_catalog><his_id>{6}</his_id><event_no>{7}</event_no><visit_number>{8}</visit_number><dept_name>{9}</dept_name><prescribe_number>{10}</prescribe_number><prescribe_sub_number>{11}</prescribe_sub_number><prescribe_operation>医嘱操作（发送、校对、停止、作废）或门诊处方操作（发送）</prescribe_operation><radiotherapy_id>放疗号</radiotherapy_id><process_name>CT定位申请单审核</process_name><process_time>CT定位申请单审核时间</process_time><extend_value_1>备用扩展1</extend_value_1><extend_value_2>备用扩展2</extend_value_2><extend_value_3>备用扩展3</extend_value_3><extend_value_4>备用扩展4</extend_value_4><extend_value_5>备用扩展5</extend_value_5><extend_value_6>备用扩展6</extend_value_6><extend_value_7>备用扩展7</extend_value_7><extend_value_8>备用扩展8</extend_value_8><extend_value_9>备用扩展9</extend_value_9></root>";
                    extraInfo = string.Format(extraInfo, pat.FormName + (record.Id > 0 ? "-更新" : "-新增"), pat.FormName, record.PatientId, record.PatientName, record.Id, record.FormId, "", record.PatientId, record.VisitId, LoginUser.DepartmentName, record.PatientId, record.PatientId);
                    ElectronicSignature es = new ElectronicSignature(LoginUser);
                    bool res = es.GetElectronicSignatureImage(es, record.NursingFormData, extraInfo, pat.FormId.ToString(), pat.FormName, PatientInfo.PATIENT_ID, PatientInfo.VISIT_ID);
                    if (!res) { MessageBox.Show("电子签名失败"); return; }
                }
                MessageBox.Show(record.Id == 0 ? "新增成功" : "更新成功");
                if (record.Id > 0) return;
                //新增成功后绑定数据
                this.Id = string.Empty;
                BindInfo(this.Id);
            }
            else
            {
                MessageBox.Show(ret.M);
            }
        }

        private void btnPrint_Click(object sender, EventArgs e)
        {
            SingleDeliveryPrint print = new SingleDeliveryPrint(LoginUser, PatientInfo, Id);
            print.ShowDialog();
        }

        private void textDiYiChanCheng_Shi_Click(object sender, EventArgs e)
        {
            SumDiYiChanCheng();
        }

        private void SumDiYiChanCheng()
        {
            if (string.IsNullOrEmpty(dateGongKouKaiQuan.Text)) return;
            if (string.IsNullOrEmpty(dataZhenSuoKaiShi.Text)) return;
            if (dataZhenSuoKaiShi.DateTime > dateGongKouKaiQuan.DateTime) return;
            TimeSpan timespan = dateGongKouKaiQuan.DateTime - dataZhenSuoKaiShi.DateTime;
            textDiYiChanCheng_Shi.Text = ((long)timespan.TotalMinutes / 60).ToString();
            textDiYiChanCheng_Fen.Text = (timespan.TotalMinutes % 60).ToString();
            //if (textDiYiChanCheng_Shi.Text.Equals("0")) textDiYiChanCheng_Shi.Text = string.Empty;
            //if (textDiYiChanCheng_Fen.Text.Equals("0")) textDiYiChanCheng_Fen.Text = string.Empty;
        }

        private void textDiYiChanCheng_Fen_Click(object sender, EventArgs e)
        {
            SumDiYiChanCheng();
        }

        private void textDiErChanCheng_Shi_Click(object sender, EventArgs e)
        {
            SumDiErChanCheng();
        }

        private void SumDiErChanCheng()
        {
            if (string.IsNullOrEmpty(dateTaiErMianChu_1.Text)) return;
            if (string.IsNullOrEmpty(dateGongKouKaiQuan.Text)) return;
            if (dateGongKouKaiQuan.DateTime > dateTaiErMianChu_1.DateTime) return;
            TimeSpan timespan = dateTaiErMianChu_1.DateTime - dateGongKouKaiQuan.DateTime;
            textDiErChanCheng_Shi.Text = ((long)timespan.TotalMinutes / 60).ToString();
            textDiErChanCheng_Fen.Text = (timespan.TotalMinutes % 60).ToString();
            //if (textDiErChanCheng_Shi.Text.Equals("0")) textDiErChanCheng_Shi.Text = string.Empty;
            //if (textDiErChanCheng_Fen.Text.Equals("0")) textDiErChanCheng_Fen.Text = string.Empty;
        }

        private void textDiErChanCheng_Fen_Click(object sender, EventArgs e)
        {
            SumDiErChanCheng();
        }

        private void textDiSanChanCheng_Shi_Click(object sender, EventArgs e)
        {
            SumDiSanChanCheng();
        }

        private void SumDiSanChanCheng()
        {
            if (string.IsNullOrEmpty(dateTaiPanMianChu.Text)) return;
            if (string.IsNullOrEmpty(dateTaiErMianChu_1.Text)) return;
            if (dateTaiErMianChu_1.DateTime > dateTaiPanMianChu.DateTime) return;
            TimeSpan timespan = dateTaiPanMianChu.DateTime - dateTaiErMianChu_1.DateTime;
            textDiSanChanCheng_Shi.Text = ((long)timespan.TotalMinutes / 60).ToString();
            textDiSanChanCheng_Fen.Text = (timespan.TotalMinutes % 60).ToString();
            //if (textDiSanChanCheng_Shi.Equals("0")) textDiSanChanCheng_Shi.Text = string.Empty;
            //if (textDiSanChanCheng_Fen.Equals("0")) textDiSanChanCheng_Fen.Text = string.Empty;
        }

        private void textDiSanChanCheng_Fen_Click(object sender, EventArgs e)
        {
            SumDiSanChanCheng();
        }

        private void textZongChanCheng_Shi_Click(object sender, EventArgs e)
        {
            SumZongChanCheng();
        }

        private void SumZongChanCheng()
        {
            long sumH = 0;
            long sumM = 0;
            if (!string.IsNullOrEmpty(textDiYiChanCheng_Shi.Text) && Regex.IsMatch(textDiYiChanCheng_Shi.Text, @"^\d+$"))
                sumH += Convert.ToInt64(textDiYiChanCheng_Shi.Text);
            if (!string.IsNullOrEmpty(textDiYiChanCheng_Fen.Text) && Regex.IsMatch(textDiYiChanCheng_Fen.Text, @"^\d+$"))
                sumM += Convert.ToInt64(textDiYiChanCheng_Fen.Text);

            if (!string.IsNullOrEmpty(textDiErChanCheng_Shi.Text) && Regex.IsMatch(textDiErChanCheng_Shi.Text, @"^\d+$"))
                sumH += Convert.ToInt64(textDiErChanCheng_Shi.Text);
            if (!string.IsNullOrEmpty(textDiErChanCheng_Fen.Text) && Regex.IsMatch(textDiErChanCheng_Fen.Text, @"^\d+$"))
                sumM += Convert.ToInt64(textDiErChanCheng_Fen.Text);

            if (!string.IsNullOrEmpty(textDiSanChanCheng_Shi.Text) && Regex.IsMatch(textDiSanChanCheng_Shi.Text, @"^\d+$"))
                sumH += Convert.ToInt64(textDiSanChanCheng_Shi.Text);
            if (!string.IsNullOrEmpty(textDiSanChanCheng_Fen.Text) && Regex.IsMatch(textDiSanChanCheng_Fen.Text, @"^\d+$"))
                sumM += Convert.ToInt64(textDiSanChanCheng_Fen.Text);

            sumH += (long)(sumM / 60);
            sumM = (long)(sumM % 60);

            textZongChanCheng_Shi.Text = sumH.ToString();
            textZongChanCheng_Fen.Text = sumM.ToString();
        }

        private void textZongChanCheng_Fen_Click(object sender, EventArgs e)
        {
            SumZongChanCheng();
        }

        void textChanFuLiKaiChnFangShiJian_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(dateTaiPanMianChu.Text)) return;
            textChanFuLiKaiChnFangShiJian.Text = dateTaiPanMianChu.DateTime.AddHours(2).ToString("yyyy-MM-dd HH:mm");
        }

        private void BtnReData_Click(object sender, EventArgs e)
        {
            BindInfo(this.Id);
        }

        private void comFenMianFangShi_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comFenMianFangShi.SelectedIndex > 0)
            {
                textFenMianFangShi_Text.Visible = false;
                textFenMianFangShi_Text.Text = string.Empty;
            }
            else
            {
                comFenMianFangShi2.Visible = true;
            }
            if (comFenMianFangShi.SelectedIndex == 6)
            {
                textFenMianFangShi_Text.Visible = true;
            }
        }

        private void comFenMianFangShi2_SelectedIndexChanged(object sender, EventArgs e)
        {
            textFenMianFangShi_Text.Visible = false;
            textFenMianFangShi_Text.Text = string.Empty;
            if (comFenMianFangShi2.SelectedIndex == 5)
            {
                textFenMianFangShi_Text.Visible = true;
            }
        }

        /// <summary>
        /// 两小时出血量统计
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void textChanHouLiangXiaoShiZongChuLiang_Click(object sender, EventArgs e)
        {
            double sumML = 0.00;
            if (!string.IsNullOrEmpty(textTaiPanMianChuShiChuXue.Text) && Regex.IsMatch(textTaiPanMianChuShiChuXue.Text, @"^(0|([1-9]\d*))(\.\d+)?$"))
                sumML += Convert.ToDouble(textTaiPanMianChuShiChuXue.Text);
            if (!string.IsNullOrEmpty(textChanHouSanShiChuXue.Text) && Regex.IsMatch(textChanHouSanShiChuXue.Text, @"^(0|([1-9]\d*))(\.\d+)?$"))
                sumML += Convert.ToDouble(textChanHouSanShiChuXue.Text);
            if (!string.IsNullOrEmpty(textSiWuChuXue.Text) && Regex.IsMatch(textSiWuChuXue.Text, @"^(0|([1-9]\d*))(\.\d+)?$"))
                sumML += Convert.ToDouble(textSiWuChuXue.Text);
            if (!string.IsNullOrEmpty(textLiuShiChuXue.Text) && Regex.IsMatch(textLiuShiChuXue.Text, @"^(0|([1-9]\d*))(\.\d+)?$"))
                sumML += Convert.ToDouble(textLiuShiChuXue.Text);
            if (!string.IsNullOrEmpty(textJiuShiChuXue.Text) && Regex.IsMatch(textJiuShiChuXue.Text, @"^(0|([1-9]\d*))(\.\d+)?$"))
                sumML += Convert.ToDouble(textJiuShiChuXue.Text);
            if (!string.IsNullOrEmpty(textYiBaiErChuXue.Text) && Regex.IsMatch(textYiBaiErChuXue.Text, @"^(0|([1-9]\d*))(\.\d+)?$"))
                sumML += Convert.ToDouble(textYiBaiErChuXue.Text);
            textChanHouLiangXiaoShiZongChuLiang.Text = sumML.ToString("F2");
        }
    }
}